<?php $time_offset = 10800; ?>

<div class="row clearfix">
    <div class="col-md-12 column">
        <h3><?php echo __('PURCHASE_TICKETS') ?></h3>
    </div>
</div>

<div class="row clearfix">
    <?php
                echo 
                    '<div class="col-md-12 column"><div class="panel panel-default"><div class="panel-heading"><h3 class="panel-title"><strong>' .
                        ( $language == 'lv' ? $movie_info->title_lv : $movie_info->title_en ) . '</strong> (' . $movie_info->year . ')' .
                    '</h3></div><div class="panel-body"><p>'.
                        '<img src="/uploads/posters/' . $movie_info->poster_small . '" style="float: left; margin-right: 10px;">' .
                        ($language == 'lv' ? mb_substr($movie_info->description_lv, 0, 400) : mb_substr($movie_info->description_en, 0, 400) ). '...</p><p>' . 
                        '<a class="btn btn-info" href="/movie/view/'. $movie_info->id .'">'. __('MOVIE_INFO') .'</a>' .
                    '</div></div></div>';
    ?>
</div>

<div class="row clearfix">
    <div class="col-md-12 column">
        <div class="col-md-10 column">
            <h4 class="center-text"><?php echo __('SHOW_INFO')?></h4>
            <div class="col-md-6 column">
                <p>
                    <?php echo __('SHOW_START')?> :<strong> <?php echo date('d.m.Y H:i', $show_info->start_time) ?> </strong><br>
                    <?php echo __('AUDITORIUM')?>: <strong> <?php echo $auditorium_info->auditorium_name ?> </strong><br>
                    <?php echo __('3D_MOVIE')?>: <strong> <?php echo $show_info->movie_3d == 1 ? 'Jā' : 'Nē' ?> </strong><br>
                    <?php echo __('LANGUAGE')?>: <strong> <?php echo __($show_info->language) ?> </strong><br>
                    <?php echo __('PRICE')?>: <strong><span id="ticket_price"><?php echo $show_info->price ?></span> EUR</strong>
                </p>
            </div> 
        </div>
    </div>
</div>

<?php if(time() + $time_offset < $show_info->start_time && $auditorium_info->id > 1): ?>
<div class="row clearfix">
    <div class="col-md-12 column">
        <?php echo Form::open(array("role" => "form", "id"=>"Reservation_form")); ?>
        <div class="row clearfix">
            <div class="col-md-10 column">
                <h4 class="center-text"><?php echo __('YOUR_INFO')?></h4>
                <div class="col-md-6 column">
                    <div class="form-group">
                        <label for="First_name"><?php echo __('FIRST_NAME')?><span style="color:red">*</span></label><?php echo Form::input('First_name', Auth::check() ? Auth::get_profile_fields('first_name') : '', array("class"=>"form-control"));?>
                    </div>  
                </div>   
                <div class="col-md-6 column">
                    <div class="form-group">
                        <label for="Last_name"><?php echo __('LAST_NAME')?><span style="color:red">*</span></label><?php echo Form::input('Last_name', Auth::check() ? Auth::get_profile_fields('last_name') : '', array("class"=>"form-control"));?>
                    </div>  
                </div>   
                <div class="col-md-6 column">
                    <div class="form-group">
                        <label for="Email"><?php echo __('EMAIL')?><span style="color:red">*</span></label><?php echo Form::input('Email', Auth::check() ? Auth::get_email() : '', array("class"=>"form-control"));?>
                    </div>  
                </div> 
                <div class="col-md-6 column">
                    <div class="form-group">
                        <label for="Phone"><?php echo __('PHONE')?></label><?php echo Form::input('Phone', '', array("class"=>"form-control"));?>
                    </div>  
                </div> 
            </div>
        </div>
        <div class="row clearfix">
            <h4 class="center-text"><?php echo __('CHOOSE_SEATS')?></h4>
            <div class="col-md-10 column">
                <?php echo Form::hidden('Show_ID', $show_info->id, array("id"=>"Show_ID")); ?>
                <table id='Reservation_table' class='cell-spacing center-text'>
                    <?php   
                            for($row = 0; $row <= $auditorium_info['rows']; $row++) {
                                echo '<tr>';
                                for($seat = 0; $seat <= $auditorium_info['seats_per_row']; $seat++) {

                                    if($row == 0 && $seat != 0) {
                                        echo '<td>'. ($seat) .'</td>';
                                        continue;
                                    } else if($row == 0 && $seat == 0) {
                                        echo '<td></td>';
                                        continue;  
                                    }

                                    if($seat == 0) {
                                       echo '<td>'. ((int)$auditorium_info['rows'] - $row + 1) .'</td>'; 
                                    } else {
                                        $is_reserved = false;
                                        foreach($reserved_seats as $reserved_seat) {
                                            if($reserved_seat['row'] == ((int)$auditorium_info['rows'] - $row + 1) && $reserved_seat['seat'] == $seat) {
                                                $is_reserved = true;
                                                break;
                                            } 
                                        }

                                        if($is_reserved) {
                                            echo '<td class="reserved-seat"></td>';
                                        } else {
                                            echo '<td class="empty-seat" id="Seat_'. ((int)$auditorium_info['rows'] - $row + 1) .'-'. $seat .'"></td>';
                                        }     
                                    } 
                                }
                                echo '</tr>';
                            }
                            echo '<tr><td></td><td colspan="'. $auditorium_info['seats_per_row'] .'"><center>ekrāns</center></tr>';
                    ?>
                </table>
            </div>
            <div class="col-md-2 column">
                <div id="Selected_seats"></div>
            </div>
        </div>
        <p>
            <?php echo __('TOTAL_PRICE')?>: <span id="total_price">0</span> EUR
        </p>
        <?php echo Form::hidden('Chosen_Seats', '', array("id"=>"Chosen_Seats", "name" => "Chosen_Seats")); ?>
        <?php echo Form::submit('SubmitButton', __('PURCHASE_TICKETS'), array("class"=>"btn btn-default", "id"=>"SubmitButton") ); ?> 
        <?php echo Form::close(); ?>
    </div>
</div>

<?php endif; ?>

<?php if(time() + $time_offset > $show_info->start_time): ?>
    <h3 style="color: red; text-align: center;"><?php echo __('SHOW_ENDED')?></h3>
<?php endif; ?>

<?php if($auditorium_info->id == 1): ?>
    <h3 style="color: red; text-align: center;"><?php echo __('SHOW_CANCELLED')?></h3>
<?php endif; ?>
